<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <script src="pdfium.js"></script>
    <script src="pdfium_render_wasm_example.js"></script>
</head>

<body>
    <canvas id="canvas" style="max-width: 100%; height: auto; border: 1px solid black;"></canvas>
    <script>
        PDFiumModule().then(async pdfiumModule => {
            const {
                initialize_pdfium_render,
                log_page_metrics_to_console,
                get_image_data_for_page
            } = wasm_bindgen;
            wasm_bindgen('pdfium_render_wasm_example_bg.wasm').then(async rustModule => {
                console.assert(
                    initialize_pdfium_render(
                        pdfiumModule,
                        rustModule,
                        false,
                    ),
                    "Initialization of pdfium-render failed!"
                );

                const targetDocument = "./test.pdf";
                await log_page_metrics_to_console(targetDocument);
                const pageIndex = 0;
                const width = 1414;
                const height = 1999;
                const canvas = document.getElementById("canvas");
                canvas.width = width;
                canvas.height = height;
                const context = canvas.getContext("2d");
                const imageData = await get_image_data_for_page(targetDocument, pageIndex, width, height);
                context.putImageData(imageData, 0, 0);
            });
        });
    </script>
</body>

</html>